//
//  AddDeviceListViewModel.swift
//  casdon_swiftUI
//
//  Created by casdon on 2025/5/20.
//

import Foundation

class AddDeviceListViewModel: ObservableObject {
    @Published var showWifiInfoPage: Bool = false
    var peripheralIDs: [UUID] = []
    var currentWifiInfo: WIFIStoreTools.WifiInfo?  {
        let ssid =  PermissionManager.shared.getWiFiSSID() ?? "";
        return WIFIStoreTools.shared.getWifiInfo(ssid: ssid)
    }
    
    init(peripheralIDs: [UUID]) {
        self.peripheralIDs = peripheralIDs
    }
    
    func start(id: UUID)
    {
        if !CiotManager.shared.wifiSSID.isEmpty && !CiotManager.shared.wifiPass.isEmpty {
            let _ = CiotManager.shared.startConnect(uid: id.uuidString, type: Ciot_Clink_Request_BLE)
        }
        
        guard let currentWifiInfo = self.currentWifiInfo else{
            showWifiInfoPage = true
            return
        }
    }
    
    func periPheralWithID(_ id: UUID) -> Peripheral?
    {
        let peripheral = CiotManager.shared.bleProvisioner.foundPeripherals.first { $0.id == id }
        return peripheral
    }
    
    
}
